package com.shiyingzi.security.controller;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.shiyingzi.common.PageableData;
import com.shiyingzi.common.ResponseData;
import com.shiyingzi.security.model.Menu;
import com.shiyingzi.security.model.Role;
import com.shiyingzi.security.model.RoleMenu;
import com.shiyingzi.security.model.User;
import com.shiyingzi.security.service.ISecurityUserService;


@RestController
public class SecurityApiController {

	@Resource(name = ISecurityUserService.BEAN_ID)
	private ISecurityUserService userService;
	
	@RequestMapping(value = "/doLogin", method = { RequestMethod.GET, RequestMethod.POST })
	public ResponseData doLogin(User user){
		return userService.doLogin(user);
	}
	
	@RequestMapping(value = "/loadUser", method = { RequestMethod.GET, RequestMethod.POST })
	public PageableData<User> loadUser(int page, int limit, User user){
		return null;
	}
	
	@RequestMapping(value = "/doAddMenu", method = { RequestMethod.GET, RequestMethod.POST })
	public ResponseData doAddMenu(Menu menu){
		Menu addMenu = userService.addMenu(menu);
		return new ResponseData(true, "添加成功");
	}
	
	@RequestMapping(value = "/doUpdateMenu", method = { RequestMethod.GET, RequestMethod.POST })
	public ResponseData doUpdateMenu(Menu menu){
		Menu modifyMenu = userService.modifyMenu(menu);
		return new ResponseData(true, "修改成功");
	}
	
	@RequestMapping(value = "/doDeleteMenu", method = { RequestMethod.GET, RequestMethod.POST })
	public ResponseData doDeleteMenu(Integer id){
		Menu menuById = userService.getMenuById(id);
		userService.deleteMenu(menuById);
		return new ResponseData(true, "删除成功");
	}
	
	@RequestMapping(value = "/doAddUser", method = { RequestMethod.GET, RequestMethod.POST })
	public ResponseData doAddUser(User user){
		System.out.println(user);
		User addUser = userService.addUser(user);
		return new ResponseData(true, "添加成功");
	}
	
	@RequestMapping(value = "/doUpdateUser", method = { RequestMethod.GET, RequestMethod.POST })
	public ResponseData doUpdateUser(User user){
		User modifyUser = userService.modifyUser(user);
		return new ResponseData(true, "修改成功");
	}
	
	@RequestMapping(value = "/doDeleteUser", method = { RequestMethod.GET, RequestMethod.POST })
	public ResponseData doDeleteUser(Integer id){
		User userById = userService.getUserById(id);
		userService.deleteUser(userById);
		return new ResponseData(true, "删除成功");
	}
	
	@RequestMapping(value = "/doAddRole", method = { RequestMethod.GET, RequestMethod.POST })
	public ResponseData doAddRole(Role role){
		Role addRole = userService.addRole(role);
		return new ResponseData(true, "添加成功");
	}
	
	@RequestMapping(value = "/doUpdateRole", method = { RequestMethod.GET, RequestMethod.POST })
	public ResponseData doUpdateRole(Role role){
		Role modifyRole = userService.modifyRole(role);
		return new ResponseData(true, "修改成功");
	}
	
	@RequestMapping(value = "/doDeleteRole", method = { RequestMethod.GET, RequestMethod.POST })
	public ResponseData doDeleteRole(Integer id){
		Role roleById = userService.getRoleById(id);
		userService.deleteRole(roleById);
		return new ResponseData(true, "删除成功");
	}
	
	@RequestMapping(value = "/doUpdateRoleMenu", method = { RequestMethod.GET, RequestMethod.POST })
	public ResponseData doUpdateRoleMenu(RoleMenu menu, boolean checked){
		return userService.doUpdateRoleMenu(menu, checked);
	}
	
	@RequestMapping(value = "/doUpdateUser1", method = { RequestMethod.GET, RequestMethod.POST })
	public ResponseData doUpdateUser1(User user){
		User modifyUser = userService.modifyUser1(user);
		return new ResponseData(true, "修改成功");
	}
}
